import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();


//分页的类型
export type Pagination = {
  current: number;
  pageSize: number;
  total?: number; // 添加 total 属性
};


//分页处理
export async function paginate(model: any, params: any, whereClause: any = {}) {
  const page = parseInt(params.page || '1');
  const pageSize = parseInt(params.pageSize || '10');

  // 添加多条件模糊查询
  const data = await model.findMany({
    where: {
      AND: [
        whereClause
      ]
    },
    skip: (page - 1) * pageSize,
    take: pageSize,
  });

  const total = await model.count({
    where: {
      AND: [
        whereClause
      ]
    },
  });

  return {
    data,
    total,
    page,
    pageSize,
  };
}